我们提供的大模型推理接口兼容openai接口规范,以下是具体示例;注意:接口都需要携带api key完成鉴权
鉴权方式
接口支持API Key 鉴权方式,具体参考API Key创建
例:
Authorization: Bearer {API Key}
Header 参数
参数名 | 类型 | 是否必填 | 示例值 |
---|---|---|---|
Authorization | string | 是 | Bearer |
获取模型列表
GET https://openapi.hhaice.com/v1/models
鉴权方式
本接口支持API Key 鉴权方式,具体参考API Key创建
对话(Chat)-文本
POST https://openapi.hhaice.com/v1/chat/completions
鉴权方式
本接口支持API Key 鉴权方式,具体参考API Key创建
Header 参数
参数名 | 类型 | 是否必填 | 示例值 |
---|---|---|---|
Content-Type | string | 是 | application/json |
Authorization | string | 是 | Bearer |
请求参数
参数名称 | 类型 | 是否必填 | 描述 | 示例值 |
---|---|---|---|---|
model | String | 是 | 要使用的模型的 ID。有关哪些模型可与聊天 API 一起使用的详细信息,请参阅模型表。 | deepseek-r1 |
messages | Array of MessageParam | 是 | 至今为止对话所包含的消息列表。包含role、content的数组 | |
temperature | integer | 否 | 使用什么采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使输出更加集中和确定。 我们通常建议改变这个或top_p但不是两者。 | 0.5 |
top_p | integer | 否 | 一种替代温度采样的方法,称为核采样,其中模型考虑具有 top_p 概率质量的标记的结果。所以 0.1 意味着只考虑构成前 10% 概率质量的标记。 我们通常建议改变这个或temperature但不是两者。 | 1 |
stream | boolean | 否 | 默认为 false 如果设置,则像在 ChatGPT 中一样会发送部分消息增量。标记将以仅数据的服务器发送事件的形式发送,这些事件在可用时,并在 data: [DONE] 消息终止流。Python 代码示例。 | false |
presence_penalty | number | -2.0 和 2.0 之间的数字。正值会根据到目前为止是否出现在文本中来惩罚新标记,从而增加模型谈论新主题的可能性。 查看有关频率和存在惩罚的更多信息。 | 0 | |
frequency_penalty | number | 默认为 0 -2.0 到 2.0 之间的数字。正值根据文本目前的存在频率惩罚新标记,降低模型重复相同行的可能性。 有关频率和存在惩罚的更多信息。 | 0 |
非流式请求示例:
{
"messages": [
{
"role": "user",
"content": "hello"
}
],
"stream": false,
"model": "deepseek-r1",
"temperature": 0.5,
"presence_penalty": 0,
"frequency_penalty": 0,
"top_p": 1
}
响应参数
参数名称 | 类型 | 描述 |
---|---|---|
id | string | 聊天完成的唯一标识符 |
choices | array | 聊天完成选项列表。如果n大于1,可以有多个选项 |
created | integer | 创建聊天完成的Unix时间戳(秒) |
model | string | 用于聊天完成的模型 |
system_fingerprint | string | 该指纹表示模型运行的后端配置 |
object | string | 对象类型,总是 chat.completion |
usage | object | 完成请求的使用统计信息 |
completion_tokens | integer | 生成的完成中的标记数 |
prompt_tokens | integer | 提示中的标记数 |
total_tokens | integer | 请求中使用的标记总数(提示 + 完成) |
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "deepseek-r1",
"system_fingerprint": "fp_44709d6fcb",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?",
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
流式请求示例:
{
"messages": [
{
"role": "user",
"content": "hello"
}
],
"stream": true,
"model": "deepseek-r1",
"temperature": 0.5,
"presence_penalty": 0,
"frequency_penalty": 0,
"top_p": 1
}
响应示例:
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
....
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":" today"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"?"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
模型对象
GET https://openapi.hhaice.com/v1/models
{
"data": [
{
"id": "deepseek-r1",
"object": "model",
"created": 1626777600,
"owned_by": "custom",
"permission": null,
"root": "deepseek-r1",
"parent": null
}
],
"object": "list"
}
Python示例
import openai
openai.api_key = 'sk-xxxxxxxxxxxxxxxxxxx'
openai.api_base = 'https://openapi.hhaice.com/v1'
def chat_with_gpt(prompt):
try:
response = openai.ChatCompletion.create(
model="deepseek-r1",
messages=[
{"role": "system", "content": "你是一个知识渊博的助手。"},
{"role": "user", "content": prompt}
]
)
message = response.choices[0].message.content
return message
except Exception as e:
print(f"发生错误: {e}")
return None
prompt = "介绍一下 Python 编程语言"
result = chat_with_gpt(prompt)
if result:
print("模型回复:")
print(result)
对接客户端
我们提供的推理服务可以提供用户直接对接三方客户端,以下是在openwebui、CherryStudio的配置,原则上所有兼容openai的客户端都支持接入我们提供商的推理服务。
OpenWebUI
方法一: 如果是docker部署方式,通过设置环境变量指定服务提供商,命令如下:
docker run -itd -p 8080:8080 \
-v $(pwd)/open-webui:/app/backend/data \
--name open-webui --restart always \
-e OPENAI_API_BASE_URL=https://openapi.hhaice.com/v1 \
-e OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
dyrnq/open-webui:main
OPENAI_API_BASE_URL: 配置服务提供商的基本 API URL
OPENAI_API_KEY:设置 服务提供商的API 密钥
方法二:如果已经部署好open webui,可以通过页面设置,具体步骤如下:
1、管理员身份登录。
2、点击右上角头像选择管理员面板。
3、选择设置 -> 外部链接
CherryStudio
提供商类型选择OpenAI